import CardScanner from '../../fanyi/cardscanner.js'
Page({
  data: {
    nr: '',
    xsbox: false,
    topimg: true
  },
  choose_gb: function() {
    this.setData({
      nr: '',
      xsbox: false,
      topimg: false,
    })
  },
  onLoad(options) {
    let that = this
    this.imgPath = options.imgPath
    this.cardScanner = new CardScanner(this)
      .on('ImageChanged', (imgPath) => {
        that.imgPath = imgPath
        console.log(imgPath)
      })
      .on('DecodeStart', (imgPath) => {
        wx.showLoading({
          title: '解析中',
          mask: true
        })
      })
      .on('DecodeComplete', (res) => {
        console.log(res.data);
        let a = res.data;
   
        
        // var text = "<view><span>姓名</span>卫兆华</view><view><span>职位</span>市场管理部总经理,中压开关事业部</view><view><span>公司</span>贵州长征电气股份有限公司,GUIZHOUCHANGZHENG ELECTRICAPPARTUSCO..LTD.</view><view><span>地址</span>贵州省遵义市上海路100号</view><view><span>邮编</span>563002</view><view><span>邮箱</span>weizhachua@126.com,Http://www.czdq.cn</view><view><span>手机</span>13017405905</view><view><span>电话</span>0852-8685056</view><view><span>传真</span>0852-8685036</view>";
        // for (var key in a)
        // {
        //   text +=  `<view><span>${key}:</span>${a[key].toString()}</view>`
        //     // console.log(key);
        //     // console.log(a[key]);	//Coding, 100
        // }
        console.log(a);
        that.setData({
          nr: a,
          xsbox: true,
          topimg: false
        })
   

        if (res.code == 0) {
          wx.showModal({
            title: '',
            content: a,
          })
        } else {
          console.log('解析失败：' + res.reason)
        }
        wx.hideLoading()
      })
  },

  onReady() {
    this.cardScanner.setImage(this.imgPath)
  }
})